package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.JobService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/job")
public class JobController {

    private final JobService jobService;

    @AnnoLog(value = "定时任务新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addJob(@RequestBody Map<String, Object> dataParam) {
        return jobService.addJob(dataParam);
    }

    @AnnoLog(value = "定时任务修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateJob(@RequestBody Map<String, Object> dataParam) {
        return jobService.updateJob(dataParam);
    }

    @AnnoLog(value = "定时任务删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteJob(@RequestBody Map<String, Object> dataParam) {
        return Result.success(jobService.deleteJob((String) dataParam.get("ids")));
    }

    @AnnoLog(value = "定时任务列表")
    @PostMapping("/list")
    public Result<?> jobList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(jobService.getJobPage(queryParam));
    }

    @AnnoLog(value = "开始任务")
    @PostMapping("/start")
    public Result<?> startJob(@RequestBody Map<String, Object> dataParam) {
        return Result.success(jobService.startJob(Long.valueOf(dataParam.get("id").toString())));
    }

    @AnnoLog(value = "停止任务")
    @PostMapping("/stop")
    public Result<?> stopJob(@RequestBody Map<String, Object> dataParam) {
        return Result.success(jobService.stopJob(Long.valueOf(dataParam.get("id").toString())));
    }

}
